<template>
	<view class="admin-picture-item-container" @tap="goEdit">
		<image @tap.prevent="showImage" class="admin-picture-item-img" :src="data.bannerInfo.pic_url" mode="aspectFit"></image>
		<view class="admin-picture-item-other">
			<view class="admin-picture-item-intro">{{data.bannerInfo.intro}}</view>
			<view class="admin-picture-btn-container">
				<button class="admin-picture-delete-btn" @tap.prevent="deleteMe">删除</button>
				<button class="admin-picture-btn" @tap.prevent="getMove(0)">上移</button>
				<button class="admin-picture-btn" @tap.prevent="getMove(1)">下移</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {onMounted,reactive,watch} from 'vue'
	export default{
		name:'admin-picture-item',
		setup(value,context){
			let data = reactive({
				bannerInfo:{},
			})
			
			onMounted(()=>{
				data.bannerInfo = value.bannerInfo;
			})
			
			watch(value, (newValue)=>{
			    data.bannerInfo = newValue.bannerInfo;
			})
			
			function getMove(v){
				console.log(v)
				if(!v){
					context.emit('moveUp',value.bannerIndex)
				}else{
					context.emit('moveDown',value.bannerIndex)
				}
			}
			
			function deleteMe(){
				context.emit('deletel',value.bannerIndex)
			}
			
			function showImage(){
				let imgArr = []
				imgArr[0] = value.bannerInfo.pic_url
				uni.previewImage({
					current:0,
					urls:imgArr
				})
			}
			
			function goEdit(){
				data.bannerInfo.index = value.bannerIndex
				uni.navigateTo({
					url:'/pages/admin/admin-picture-edit?picInfo='+encodeURIComponent(JSON.stringify(data.bannerInfo))
				})
			}
			
			return {
				data,
				getMove,
				deleteMe,
				showImage,
				goEdit
			}
			
			
		}
	}
</script>

<style scoped>
	.admin-picture-item-container{
		height: 145rpx;
		margin: 10rpx ;
		display: flex;
		border-bottom: 2rpx solid #515151;
	}
	
	.admin-picture-item-img{
		width: 180rpx;
		height: 140rpx;
	}
	
	.admin-picture-item-other{
		width: 500rpx;
		margin-left: 10rpx;
		
	}
	
	.admin-picture-item-intro{
		text-overflow: -o-ellipsis-lastline;
		overflow: hidden;
		text-overflow:ellipsis;
		display: -webkit-box;
		-webkit-line-clamp: 1;
		line-clamp: 1;
		-webkit-box-orient: vertical;
		height: 70rpx;
		line-height: 70rpx;
		font-size: 32rpx;
		width: 500rpx;
		margin-left: 10rpx;
	}
	
	.admin-picture-btn-container{
		height: 70rpx;
		margin-top: 15rpx;
		width: 500rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
	}
	
	.admin-picture-delete-btn{
		width: 110rpx;
		height: 43rpx;
		font-size: 25rpx;
		line-height: 40rpx;
		background-color: #DE6868;
		color: white;
	}
	
	.admin-picture-btn{
		width: 110rpx;
		height: 43rpx;
		font-size: 25rpx;
		line-height: 40rpx;
		background-color: #9BCDD2;
		color: white;
	}
</style>